<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billNo">
              <a-input :disabled=formDisabled v-model="model.billNo" placeholder="请输入单据编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposer">
              <a-input :disabled=formDisabled v-model="model.proposer" placeholder="请输入申请人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicationTime">
              <j-date :disabled=formDisabled placeholder="请选择申请时间" v-model="model.applicationTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="申请车辆" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicationCar">
              <a-input :disabled=formDisabled v-model="model.applicationCar" placeholder="请输入申请车辆"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预定时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="presetTime">
              <j-date :disabled=formDisabled placeholder="请选择预定时间" v-model="model.presetTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposerdeptid">
              <a-input :disabled=formDisabled v-model="model.proposerdeptid" placeholder="请输入申请部门"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="费用所属团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamId">
              <a-input :disabled=formDisabled v-model="model.teamId" placeholder="请输入费用所属团队"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用车类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useCarType">
              <a-input :disabled=formDisabled v-model="model.useCarType" placeholder="请输入用车类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="还车时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carBackTime">
              <j-date :disabled=formDisabled placeholder="请选择还车时间" v-model="model.carBackTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName">
              <a-input :disabled=formDisabled v-model="model.projectName" placeholder="请输入项目名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useDay">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.useDay" placeholder="请输入使用天数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用公里数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useMileage">
              <a-input :disabled=formDisabled v-model="model.useMileage" placeholder="请输入使用公里数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="租金（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rent">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.rent" placeholder="请输入租金（元）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公里数费用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mileageCost">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.mileageCost" placeholder="请输入公里数费用" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="费用合计" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costTotal">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.costTotal" placeholder="请输入费用合计" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ErpReportCarCostInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/api/erp/modules/workbench/report/erpReportCarCostInfo/add",
          edit: "/api/erp/modules/workbench/report/erpReportCarCostInfo/edit",
          queryById: "/api/erp/modules/workbench/report/erpReportCarCostInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
